/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package roomarrange;

import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Button;
import com.sun.webui.jsf.component.Calendar;
import com.sun.webui.jsf.component.DropDown;
import com.sun.webui.jsf.component.TextField;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FacesException;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @version modiTime.java
 * @version Created on 2010-7-17, 12:22:00
 * @author ben
 */

public class modiTime extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }
    private DropDown dropDown3 = new DropDown();

    public DropDown getDropDown3() {
        return dropDown3;
    }

    public void setDropDown3(DropDown dd) {
        this.dropDown3 = dd;
    }
    private Button button1 = new Button();

    public Button getButton1() {
        return button1;
    }

    public void setButton1(Button b) {
        this.button1 = b;
    }
    private Calendar calendar3 = new Calendar();

    public Calendar getCalendar3() {
        return calendar3;
    }

    public void setCalendar3(Calendar c) {
        this.calendar3 = c;
    }
    private DropDown dropDown1 = new DropDown();

    public DropDown getDropDown1() {
        return dropDown1;
    }

    public void setDropDown1(DropDown dd) {
        this.dropDown1 = dd;
    }
    private Calendar calendar2 = new Calendar();

    public Calendar getCalendar2() {
        return calendar2;
    }

    public void setCalendar2(Calendar c) {
        this.calendar2 = c;
    }
    private DropDown dropDown2 = new DropDown();

    public DropDown getDropDown2() {
        return dropDown2;
    }

    public void setDropDown2(DropDown dd) {
        this.dropDown2 = dd;
    }
    private TextField docno = new TextField();

    public TextField getDocno() {
        return docno;
    }

    public void setDocno(TextField tf) {
        this.docno = tf;
    }
    private TextField cname = new TextField();

    public TextField getCname() {
        return cname;
    }

    public void setCname(TextField tf) {
        this.cname = tf;
    }
    private TextField casecause = new TextField();

    public TextField getCasecause() {
        return casecause;
    }

    public void setCasecause(TextField tf) {
        this.casecause = tf;
    }
    private TextField caseno = new TextField();

    public TextField getCaseno() {
        return caseno;
    }

    public void setCaseno(TextField tf) {
        this.caseno = tf;
    }

    // </editor-fold>

    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public modiTime() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
        
        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("modiTime Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
        if (!this.isPostBack()) {
            this.getDocno().setText("");
            this.getCname().setText("");
            this.getCaseno().setText("");
            this.getCasecause().setText("");
        }

    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    public String button3_action() {
        // TODO: Replace with your code
        int li_roomid;
        int li_cnt;
        if (this.getDropDown3().getSelected() == null) {
            info("请选择工作区");
            return null;
        }
        //获取该会议室的类型
        ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringConfig.xml");
        DataSource ds = (DataSource) ctx.getBean("dataSourceDBDirect");
        //DataSource ds = (DataSource) ctx.getBean("dataSourcePool");
        DataJdbcDao taskDao = new DataJdbcDao();
        taskDao.setDataSource(ds);

        String sapp = this.getSessionBean1().getSApp();
        //工作区的房间编号
        li_roomid = (Integer)this.getDropDown3().getValue();
        String sMtId = taskDao.getNowMeetingId(li_roomid, sapp);
        sMtId = sMtId.trim();
        li_cnt = sMtId.length();
        if(li_cnt<1){
            info("提示，当前，选中的工作区没有被办案部门占用，请重新选择！");
            return null;
        }
        this.getSessionBean1().setSUUID(sMtId);
        meetings mt=new meetings();
        mt = taskDao.getMeeting(sMtId,sapp);
        this.getDropDown1().setValue(mt.getSStime());
        this.getDropDown2().setValue(mt.getSEtime());
        this.getCalendar2().setValue(mt.getSSdate());
        this.getCalendar3().setValue(mt.getSEdate());
        this.getDocno().setText(mt.getCdocno());
        this.getCname().setText(mt.getSCname());
        this.getCaseno().setText(mt.getCcaseno());
        this.getCasecause().setText(mt.getCcasecause());

//        this.getDropDown1().setValue(ls_stime);
//        this.getDropDown2().setValue(ls_etime);
//        this.getSessionBean1().setSSdate(ls_stime);
//        this.getSessionBean1().setSEdate(ls_etime);
//        this.getSessionBean1().setIroomid(li_roomid);
       
        this.getButton1().setDisabled(false);

        return null;
    }

    public String button1_action() throws ParseException {
        // TODO: Replace with your code
        String ls_edate = "";
        String ls_etime = "";
        String ls_year = "";
        ls_etime = this.getDropDown2().getSelected().toString();
        Date ld_edate = null;
        Date ldt_sdate= null;
        Date ldt_edate= null;
        Date ldt_now = null;
        long ll_s=0;
        long ll_e=0;
        long ll_now=0;
        int li_cnt=0;
        int li_seq=0;
        ld_edate = (Date) this.getCalendar2().getValue();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        ls_edate = sdf.format(ld_edate);
        ls_edate = ls_edate + " " + ls_etime + ":00";
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy");

        try {
            ldt_edate = sdf2.parse(ls_edate);
        } catch (ParseException ex) {
            Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
        }
        ldt_now = new Date();
        String suuid = this.getSessionBean1().getSUUID();
        //获取该会议室的类型
        ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringConfig.xml");
        DataSource ds = (DataSource) ctx.getBean("dataSourceDBDirect");
        //DataSource ds = (DataSource) ctx.getBean("dataSourcePool");
        DataJdbcDao taskDao = new DataJdbcDao();
        taskDao.setDataSource(ds);
        taskDao.updateWorkEndTime(suuid, ls_edate);
        info("更新成功！");
        return null;
    }
    
}

